﻿using MediatR;
using W.Purchase.API.Application.Command.FinanceTypeCommand;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.FinanceTypeCommandHandler
{
    public class FinanceTypeCreateCommandHandler:IRequestHandler<FinanceTypeCreateCommand,int>
    {
        private readonly IFinanceTypesRepository _ifinanceTypesRepository;
        public FinanceTypeCreateCommandHandler(IFinanceTypesRepository ifinanceTypesRepository)
        {
            _ifinanceTypesRepository = ifinanceTypesRepository;
        }

        public async Task<int> Handle(FinanceTypeCreateCommand request, CancellationToken cancellationToken)
        {
            return await _ifinanceTypesRepository.AddAsync(new Domain.FinanceType
            {
                FinanceTypeId = request.FinanceTypeId,
                FinanceTypeNo=request.FinanceTypeNo,
                FinanceTypeName=request.FinanceTypeName,
                FinanceTyperemark=request.FinanceTyperemark,
                office_id=request.office_id,
                user_id=request.user_id,
                CreateName=request.CreateName,
                CreateTime=DateTime.Now,
                IsDelete=false
            });
        }
    }
}
